#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-08-15 10:31:46
# @Author  : yangchaojun (YYChildren@gmail.com)
# @Link    : https://git.mingchao.com/yangchaojun
# @Version : 

from configparser import RawConfigParser
import codecs

class _Singleton(object):
    _instance = None
    def __new__(cls, *args, **kw):
        if not cls._instance:
            cls._instance = super(_Singleton, cls).__new__(cls, *args, **kw)  
        return cls._instance

class _config(_Singleton, dict):
    """docstring for _config"""
    def __init__(self):
        super(_config, self).__init__()
        self.load_conf()

    def load_conf(self):
        '''
        返回配置字典
        '''
        conf_path = 'config/common.ini'
        self.conf_path=conf_path
        confparser = RawConfigParser()
        confparser.readfp(codecs.open(conf_path, "r", "utf-8"))
        for section in confparser.sections():
            self.update({"%s:%s" % (section, k) :v for k,v in confparser.items(section)})

CONFIG=_config()
